<%@taglib prefix="html" uri="/tags/struts-html" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="com.DAO.*,java.util.*,com.beans.*,java.text.*"%>
    
 
    <%!int i=0;String categoryId=null;
            String str=null;
            int totalpages=0;
 %>
 
  <%@taglib prefix="getData" uri="/WEB-INF/CustomTagDescriptor.tld" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel = "stylesheet" href = "style/Global.css" />
<script language="javaScript" type="text/javascript" src="scripts/calendar.js"></script>
<script language="javaScript" type="text/javascript" src="scripts/Global.js"></script>
   <link href="style/calendar.css" rel="stylesheet" type="text/css">
</head>

<%

     
     
      
	  NoticeDAO noticeDAO=new NoticeDAO();
	  
	  try{
		  			int noticecount=noticeDAO.getNoticeCountByCategory(0);
		  
	                if(noticecount%5==0){
		  					totalpages=noticecount/5;
	                }
	                else
	                {
	                	    totalpages=(noticecount/5)+1;
	                }
	  
	  System.out.println("Total pages are...."+totalpages);
	  
	  }
	  catch(Exception e){
		  System.out.println("Error in count notices....");
	  }
	  
	 

if(request.getParameter("pageno")!=null){
		i=Integer.parseInt(request.getParameter("pageno"));
}	  
	  
else {	  
String op=request.getParameter("op");
System.out.print("op is..........."+op);

if(op!=null)
{    
    if(op.equals("next"))
    {
    	   
    	   String counter=request.getParameter("counter");
    	   if(counter==null)
    	   {
    		   i=0;    		   
    	   }
    	   else
    	   {
    		   
    		    i=Integer.parseInt(counter)+1;
    	   }
    }   
    else
    {
    	String counter=request.getParameter("counter");
    	if(counter==null){
 		   i=0;    		   
 	   }
 	   else if(Integer.parseInt(counter)>0){
 		     i=Integer.parseInt(counter)-1;
 	   }
    	
    }
}   
else{
	i=0;
}


}
%>



	<%	str=i+"";
		System.out.println("Cursor value is........."+Integer.parseInt(str));
	%>

<body>
	<fieldset id = "postform">
		<img src = "image/Notice_Board.png" alt = "Notice_Board" align="top" width = "140" height = "160">
		<form  method="post" action="NoticeForm.do">
			
				<table>
				<tr>
			
					<td>
						<div class = "titletext">Category:</div>
					</td>
					<td>
						<select class = "inputelement" name="categoryName">
							<%!					
								CategoryDAO categorydao = new CategoryDAO();
							    ArrayList<CategoryForm> cl=null;
							%>
							<%					
							String user=(String)session.getAttribute("user_type");
							try {
							
								
								cl = categorydao.get();
								for(int i = 0; i < cl.size(); i++){
									if( !cl.get(i).getName().equals("Birthday")){
												if(!cl.get(i).getName().equals("Announcements") 
														
														&& !cl.get(i).getName().equals("Client Appreciation")) {
													%><option><%=cl.get(i).getName() %></option><%
												} else if(user.equals("admin")) {
													%><option><%=cl.get(i).getName() %></option><%
												}}								
									}
								} catch(Exception e) {
									
								}
								%>
						</select>						
					</td>
						<td>
						<div class = "titletext">Expiry Date:</div>
					</td>
					<td>
					
		
							
							
							<%
								Date currentDate = new Date();
								Date expDate = new Date();
								expDate.setTime(currentDate.getTime()+ (15*24*60*60*1000));
								SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
							%>
							<input id = "datum" class = "inputelement" readonly="readonly" type="text" name="expirationDate" value = "<%= sdf.format(expDate) %>">
							
      						<a href="#" onClick="setYears(2012, 2030);
       showCalender(this, 'expirationDate');">
      <img src="image/calender.png"></a>
      <br><html:errors property="expirationDate"/>
      
					</td>
				</tr>
				<tr>
					<td>
						<div class = "titletext">Title:</div>
					</td>
					<td colspan = "3">
						<input class = "inputelementlarge" type = "text"  name="title">
						<br><html:errors property="title"/>
						<html:errors property="titlelength"/>
					</td>
				</tr>				
				<tr>
					<td>
						<div class = "titletext">Description:</div>
					</td>
					<td colspan = "3">
						<textarea class = "inputelementlarge" rows="3"  name="description"></textarea>
						<br><html:errors property="description"/>
						<html:errors property="descriptionlength"/>
					</td>
				</tr>
				<tr>
					<td colspan = "4">
						<input  id = "btnsubmit" type = "image" onclick="form.submit();" name = "submit" src="image/27.jpg">
					</td>
				</tr>
				</table>
							
							<table id="calenderTable">
        <tbody id="calenderTableHead">
          <tr>
            <td colspan="4" align="center">
	          <select onChange="showCalenderBody(createCalender(document.getElementById('selectYear').value,
	           this.selectedIndex, false));" id="selectMonth">
	              <option value="0">Jan</option>
	              <option value="1">Feb</option>
	              <option value="2">Mar</option>
	              <option value="3">Apr</option>
	              <option value="4">May</option>
	              <option value="5">Jun</option>
	              <option value="6">Jul</option>
	              <option value="7">Aug</option>
	              <option value="8">Sep</option>
	              <option value="9">Oct</option>
	              <option value="10">Nov</option>
	              <option value="11">Dec</option>
	          </select>
            </td>
            <td colspan="2" align="center">
			    <select onChange="showCalenderBody(createCalender(this.value, 
				document.getElementById('selectMonth').selectedIndex, false));" id="selectYear">
				</select>
			</td>
            <td align="center">
			    <a href="#" onClick="closeCalender();"><font color="#003333" size="+1">X</font></a>
			</td>
		  </tr>
       </tbody>
       <tbody id="calenderTableDays">
         <tr style="">
           <td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>
         </tr>
       </tbody>
       <tbody id="calender"></tbody>
    </table>

<!-- End Calender Script  --> 
				
				 <!-- Calender Script  --> 

    
      
		</form>
		



	</fieldset>
	<%str=i+""; %>
	
	<getData:notice1 cursor="<%=str%>" category="0"/>
	
		
	<center> 
	<div id = "pager">	 
	<%if(Integer.parseInt(str)>0)
	{%>
	<a id = "btnprev" href="noticeform-1.jsp?counter=<%=str%>&op=pre"> <img src = "image/46.jpg" alt = "Previous"></a>
	<%} %>
	
	<div id = "pageno">
	<%if(totalpages != 0) { %>
	<%=i+1%> of <%=totalpages%>
	<%} %>
	</div>
	<!-- Changes for pages link 
				<% if(totalpages>1) {
	    for(int i=0;i<totalpages;i++){
	 %>   	
	    	<a class = "anchor" href="noticeform-1.jsp?pageno=<%=i%>"><%=i+1%> </a> &nbsp;
	   <% 
	        	   
	    }}%> 
	 -->   
	<%if(Integer.parseInt(str)<totalpages-1){ %>
	<a id = "btnnext" href="noticeform-1.jsp?counter=<%=str%>&op=next"><img src = "image/43.jpg" alt = "Next"> </a>
	<%} %>	 
	</div>
	</center>
	
	
	
	
	
</body>


</html>